class Teleporteur
  attr_reader :occuper
  require "sqlite3"
  
  def initialize(parking)
    @parking = parking
    @occuper = false
  end
  
  
  def garer_vehicule(vehicule,id)
    @occuper = true
    @parking.places[id].vehicule = vehicule
    @occuper = false
  end
  
  def recuperer_vehicule(ticket)
    @occuper = true
    if @parking.get_place_by_ticket(ticket)
      immat = @parking.get_place_by_ticket(ticket).vehicule.immat
      @parking.get_place_by_ticket(ticket).vehicule = nil
      @parking.get_place_by_ticket(ticket).ticket = nil
    end
    if @parking.db.execute("select id from Places where immatriculation = '#{immat}'")[0]
      place = @parking.db.execute("select id from Places where immatriculation = '#{immat}'")[0][0]
    end
    if place
      @parking.db.execute("delete from Places where immatriculation = '#{immat}'")     
      @parking.nbDispo+=1
      #@parking.afficher_panneau
      @occuper = false
      return true
    end
    @occuper = false
    return  false
  end
  
end